package cn.cjxy.springboot_mybatis01.service.impl;

import cn.cjxy.springboot_mybatis01.domain.User;
import cn.cjxy.springboot_mybatis01.mapper.UserMapper;
import cn.cjxy.springboot_mybatis01.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * MVC
 *
 * Service层实现类，接口的具体实现
 * 只关注业务实现，不直接操作数据库
 * 需要涉及到数据的操作就去调用mapper层
 */
@Service
public class UserServiceImpl implements IUserService {
    //注入mapper层
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public User findById(int id) {
        return userMapper.findById(id);
    }

    @Override
    public void insert(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void delete(String name) {
        userMapper.delete(name);
    }
}
